//
//  AccountManagementController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/14.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AccountManagementController.h"
#import "AccountManagementCell.h"
#import "ChangePasswordController.h"


@interface AccountManagementController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSource;

@end

@implementation AccountManagementController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账号管理";
    [self.view addSubview:self.listView];
}

#pragma mark --UITableViewDelegate,UITableViewDataSource
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 38.0f;
    }
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return UIView.new;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 38)];
        view.backgroundColor = UIColorFromRGB(0xF5F7F5);
        
        UILabel * label = UILabel.new;
        label.text = @"第三方账号绑定";
        label.font = PingFangSC_Regular(16);
        label.textColor=UIColorFromRGB(0x959E97);
        label.textAlignment = NSTextAlignmentCenter;
        
        [view addSubview:label];
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
        }];
        
        return view;
    }
    return UIView.new;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return ((NSArray *)self.dataSource[section]).count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AccountManagementCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AccountManagementCell class])];
    cell.indexPath = indexPath;
    cell.dic = self.dataSource[indexPath.section][indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0 && indexPath.row == 0) {
        [self.navigationController pushViewController:[ChangePasswordController new] animated:YES];
    }
}
#pragma mark ---懒加载
-(UITableView*)listView{
    if(!_listView){
        _listView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _listView.dataSource = self;
        _listView.delegate =self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[AccountManagementCell class] forCellReuseIdentifier:NSStringFromClass([AccountManagementCell class])];
        _listView.tableFooterView = UIView.new;
        [_listView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
        _listView.separatorColor = SeparatorColor;
        _listView.backgroundColor = KWhiteColor;
    }
    return _listView;
}

-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        NSArray * array = @[@[@{@"leftName":@"修改密码",@"rightName":@""},@{@"leftName":@"手机号",@"rightName":@"186****1233"},@{@"leftName":@"邮箱",@"rightName":@"126****7777@163.com"}],@[@{@"leftName":@"微信",@"rightName":@"已绑定"},@{@"leftName":@"微博",@"rightName":@"未绑定"}]];
        _dataSource =[NSMutableArray array];
        [_dataSource addObjectsFromArray:array];
    }
    return _dataSource;
}
@end
